package backtrack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description: 78. 子集
 * User: Li_yizYa
 * Date: 2025/6/17
 * Time: 16:00
 */
public class Solution8 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> ret = new ArrayList<>();
        if (nums == null || nums.length == 0) {
            return ret;
        }
        List<Integer> tmp = new ArrayList<>();
        backTracking(ret, tmp, nums, 0);
        return ret;
    }

    private void backTracking(List<List<Integer>> ret, List<Integer> tmp, int[] nums, int index) {
        if (index > nums.length) {
            return;
        }
        ret.add(new ArrayList<>(tmp));
        for (int i = index; i < nums.length; i++) {
            tmp.add(nums[i]);
            backTracking(ret, tmp, nums, i + 1);
            tmp.remove(tmp.size() - 1);
        }
    }

}
